#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;


int triangleNumber(vector<int>& nums) {
    int count = 0;
    sort(nums.begin(), nums.end());
    int n = nums.size();
    for (int i = n - 1; i >= 0; i--)
    {
        int l = 0;
        int r = i - 1;
        while (nums[r] + nums[l] <= nums[i]) {
            l++;
        }
        count += r - l;

    }
    return count;
}

//int main() 
//{
//    vector<int> nums = { 2,2,3,4 };
//    int  ret = triangleNumber(nums);
//    cout << ret;
//
//    return 0;
//}